package com.baiyun.controller.admin;

import com.baiyun.Result.Result;
import com.baiyun.entity.Inventory;
import com.baiyun.entity.Orders;
import com.baiyun.service.InventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/inventorys")
@RequiredArgsConstructor
@Api(tags = "管理员端——库存管理")
public class InventoryController {

    private final InventoryService inventoryService;

    /**
     * 查询所有库存
     *
     * @return
     */
    @GetMapping()
    @ApiOperation("查询所有库存")
    public Result<List<Inventory>> selectAllInventory() {
        log.info("查询所有库存");
        return Result.success(inventoryService.selectAllInventory());
    }

    /**
     * 添加库存
     * @param inventory
     * @return
     */
    @PostMapping()
    @ApiOperation("添加库存")
    public Result addInventory(@RequestBody Inventory inventory) {
        log.info("添加库存");
        inventoryService.addInventory(inventory);
        return Result.success();
    }

    /**
     * 修改库存
     */
    @PutMapping()
    @ApiOperation("修改库存")
    public Result updateInventory(@RequestBody Inventory inventory) {
        log.info("修改库存");
        inventoryService.updateInventory(inventory);
        return Result.success();
    }

    /**
     * 删除库存
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除库存")
    public Result deleteInventory(@ApiParam("库存id") @PathVariable("id") Integer id) {
        log.info("删除库存");
        inventoryService.deleteInventory(id);
        return Result.success();
    }

    /**
     * 根据商品名称查询库存
     * @param tname
     * @return
     */
    @GetMapping("/{tname}")
    @ApiOperation("根据商品名称查询库存")
    public Result<List<Inventory>> selectInventoryByName(@ApiParam("茶名称")@PathVariable("tname") String tname){
        return Result.success(inventoryService.selectInventoryByName(tname));
    }



}
